package com.opennews.openplatform.service;

import lombok.RequiredArgsConstructor;
import org.apache.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@Service
public class ProductService {
    public List<Map<String, Object>> list(List<String> ids) {
        List<Map<String, Object>> result = new ArrayList<>();

        for (int i = 0; i < ids.size(); i++) {
            result.add(Map.of(
                    "id", ids.get(i),
                    "title", "Product-" + (i + 1)
            ));
        }

        return result;
    }

    @GlobalTransactional
    //    @Transactional
    public void testTransaction() {
        //        dslContext.update(BANK)
        //                .set(BANK.SHORT_NAME, BANK.SHORT_NAME.concat("-21"))
        //                .set(BANK.NAME, BANK.NAME.concat("-21"))
        //                .where(BANK.ID.eq("402881396f36d34b016f36d3982a0000"))
        //                .execute();
        //
        //        dslContext.update(BANK)
        //                .set(BANK.SHORT_NAME, BANK.SHORT_NAME.concat("-22"))
        //                //                .set(BANK.NAME, (String) null)
        //                .where(BANK.ID.eq("402881396f36d34b016f36d3982a0000"))
        //                .execute();
        //
        //        throw new RuntimeException();
    }
}
